#include "flyweight.h"

void WhitePiece::draw(const Position &positon)
{
    std::cout << "在{" <<positon.m_x << ","<<positon.m_y<<"}处下白棋" << std::endl;
}

void BlackPiece::draw(const Position &positon)
{
    std::cout << "在{" <<positon.m_x << ","<<positon.m_y<<"}处下黑棋" << std::endl;
}

Piece *PieceFactory::getPiece(Color color)
{
    auto it = m_pieces.find(color);
    if(it==m_pieces.end())
    {
        Piece* tmp = nullptr;
        if(color == White)
            tmp = new WhitePiece();
        else
            tmp = new BlackPiece();
        m_pieces.insert(std::make_pair(color,tmp));
        return tmp;
    }
    else{
        return it->second;
    }
}


